package itcz.example.pattern.behavior_type.state.demo_AI;

/**
 * @ClassName: Elevator
 * @Author: ITCZ
 * @Date: 2025-07-26
 * @Description: 状态模式-上下文角色
 */
public class Elevator {

    private LiftState currentState;

    public Elevator() {
        // 初始为停止状态
        currentState = new StopState();
    }

    public void setState(LiftState state) {
        this.currentState = state;
    }

    public void open() {
        currentState.open();
        if (currentState instanceof CloseState || currentState instanceof StopState) {
            setState(new OpenState());
        }
    }

    public void close() {
        currentState.close();
        if (currentState instanceof OpenState) {
            setState(new CloseState());
        }
    }

    public void run() {
        currentState.run();
        if (currentState instanceof CloseState) {
            setState(new RunState());
        }
    }

    public void stop() {
        currentState.stop();
        if (currentState instanceof RunState) {
            setState(new StopState());
        }
    }

    public LiftState getCurrentState() {
        return currentState;
    }
}
